﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;

namespace GK320_Helper
{
    /// <summary>
    /// TileWindow.xaml 的交互逻辑
    /// </summary>
    public partial class TileWindow : MetroWindow
    {
        public TileWindow()
        {
            InitializeComponent();
        }

        private void OpenIssue_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start("https://github.com/hanning-wang/GK320-Helper/issues");
        }

        private void OpenGithub_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start("https://github.com/hanning-wang/GK320-Helper/");
        }

        private void Install_Software_Click(object sender, RoutedEventArgs e)
        {
            MainWindow r = new MainWindow();
            r.Show();
        }

        private async Task OpenThanks_ClickAsync(object sender, RoutedEventArgs e)
        {
            

        }

        private async void OpenThanks_Click(object sender, RoutedEventArgs e)
        {
            var controller = await this.ShowProgressAsync("Please wait...", "Progress message");
            //Thread.Sleep(1000);
            //controller.Maximum = 10;
            //controller.Minimum = 0;
            //for (int i = 0; i <= 1000000; i++)
            //{
            //    controller.SetProgress((double)i);
            //}
            if (1 == 1) controller.CloseAsync();
        }

        private void UIMod_Click(object sender, RoutedEventArgs e)
        {
            UserInterface l = new UserInterface();
            l.Show();
        }

        private void OpenAbout_Click(object sender, RoutedEventArgs e)
        {

        }

        private async void CheckConnectivity_Click(object sender, RoutedEventArgs e)
        {
            var controller = await this.ShowProgressAsync("Please wait...", "Progress message");
            
        }

        private async void OpenSettings_Click(object sender, RoutedEventArgs e)
        {
            var controller = await this.ShowProgressAsync("Please wait...", "Opening Settings");
            string str0 = "adb shell am start com.android.settings";
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            p.StandardInput.WriteLine(str0 + "&exit");
            p.StandardInput.AutoFlush = true;
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();
            controller.CloseAsync();
            await this.ShowMessageAsync("接下来操作", "设置已经打开，请在手机端看看！");
        }

        private async void Manager_Click(object sender, RoutedEventArgs e)
        {
            var controller = await this.ShowProgressAsync("Please wait...", "Changing Settings");
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            p.StandardInput.WriteLine("adb shell setprop persist.sys.usb.config mtp" + " & exit");
            p.StandardInput.AutoFlush = true;
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            p.Close();
            controller.CloseAsync();
            await this.ShowMessageAsync("接下来操作", "请重新插拔手机Type-C线，并在此电脑中管理手机");
        }
    }
}
